<template>
  <div>
    <div class="loginBox">
      <div class="login_wat">
        <div class="loginPNG"></div>
        <!-- 123 -->
        <el-form ref="form" :model="form" :rules="rules">
          <!-- prop属性值需要与绑定值同名 -->
          <el-form-item prop="name">
            <el-input v-model="form.name" prefix-icon="el-icon-user"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              v-model="form.password"
              prefix-icon="el-icon-view"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">立即登陆</el-button>
            <el-button @click="restFormFile">重置</el-button>
            <span class="newCliam">还没有账号？点击创建</span>
          </el-form-item>
        </el-form>
        <div class="avarage_area">
          <img
            src="@/assets/logo.png"
            width="70px"
            height="70px"
            class="avarage_img"
          />
        </div>
        <!-- 123 -->
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    let validateAdmin = (rule, value, callback) => {
      if (value == "") {
        callback(new Error("请输入账户"));
      } else {
        callback();
      }
    };
    let validatePass = (rule, value, callback) => {
      if (value == "") {
        callback(new Error("请输入密码"));
      } else {
        callback();
      }
    };
    return {
      form: {
        name: "",
        password: "",
      },
      //传递信息的表单
      passForm: {},
      rules: {
        name: [{ validator: validateAdmin, trigger: "blur" }],
        password: [{ validator: validatePass, trigger: "blur" }],
      },
    };
  },
  methods: {
    onSubmit() {
      let that = this;
      this.$refs.form.validate(async (valid) => {
        if (!valid) return;
        let resultReturn = await this.$http.post("/login", this.form);
        console.log(resultReturn, "234");
        if (resultReturn.data == "添加成功" && resultReturn.status == 200) {
          that.$message({
            message: "登录成功！",
            type: "success",
          });
          console.log("登陆成功");
        } else {
          that.$message({
            message: "登录失败！",
            type: "error",
          });
          console.log("登陆失败");
        }
      });
      //token村sess
      //   window.sessionStorage.setItem()
    },
    restFormFile() {
      this.form = {
        name: "",
        password: "",
      };
    },
  },
};
</script>

<style scoped>
.loginBox {
  width: 100vw;
  height: 100vh;
  background-color: #2d4d6d;
  position: relative;
}
.newCliam {
  font-size: 12px;
  text-decoration: underline;
  color: #ccc;
  cursor: pointer;
  margin-left: 20px;
}
.loginPNG {
  width: inherit;
  height: 50px;
  text-align: center;
  line-height: 50px;
  font-size: 20px;
  color: lightskyblue;
}
.login_wat {
  width: 400px;
  height: 250px;
  border: 1px solid #ccc;
  background-color: #fff;
  padding: 20px 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -70%);
}
.avarage_area {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background-color: #fff;
  /* border: 1px solid red; */
  position: absolute;
  top: -50px;
  left: 150px;
}
.avarage_img {
  transform: translate(21%, 26%);
  /* border: 1px solid red; */
}
</style>